package com.lq.educationsystem.lqsubject.service.impl;

import com.lq.educationsystem.common.util.*;
import com.lq.educationsystem.common.vo.SubjectPageVo;
import com.lq.educationsystem.lqsubject.entiy.SubjectTb;
import com.lq.educationsystem.lqsubject.mapper.SubjectTbMapper;
import com.lq.educationsystem.lqsubject.service.SubjectBaseService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SubjectBaseImpl implements SubjectBaseService {
    @Autowired
    SubjectTbMapper subjectTbMapper;
    //调用mapper
    @Override
    public void insetInfo(SubjectTb subjectTb) {
        int row = subjectTbMapper.insertSelective(subjectTb);

        System.out.println("Subject插入数据时影响的行数"+row);

    }

    @Override
    public void deleteById(Integer subjectId) {
        int row = subjectTbMapper.deleteByPrimaryKey(Long.valueOf(subjectId));

        System.out.println("Subject删除数据时影响的行数"+row);
    }

    @Override
    public void updateInfo(SubjectTb subjectTb) {
        int row = subjectTbMapper.updateByPrimaryKeySelective(subjectTb);

        System.out.println("Subject更新数据时影响的行数"+row);
    }

    @Override
    public Result queryById(Integer subjectTb) {

        SubjectTb subjectInfo = subjectTbMapper.selectByPrimaryKey(Long.valueOf(subjectTb));
        System.out.println("查询的消息是:"+subjectInfo);
        return ResultBuild.buildOk(new Result<SubjectTb>(),subjectInfo);
    }

    @Override
    public ResultPage<SubjectTb> queryList(SubjectPageVo subjectPageVo) {
        //创建页面
        Integer page = subjectPageVo.getPage();
        Integer pageSize = subjectPageVo.getPageSize();
        int start = PageUtil.getStart(page, pageSize);

        //数据获取
        SubjectTb subjectTb = new SubjectTb();
        BeanUtils.copyProperties(subjectPageVo,subjectTb);

        //数据插入

        List<SubjectTb> subjectTbs =  subjectTbMapper.queryList(start,pageSize,subjectTb);

        int counts=0;

        counts= subjectTbMapper.queryCount(subjectTb);
        return ResultPageBuild.pageBuildOk(new ResultPage<SubjectTb>(),page,pageSize,counts,subjectTbs);
    }

    @Override
    public ResultPage<SubjectTb> queryBatchSubjectInfoBySubjectIdList(List<Integer> subjectIdListInfo) {
        //批量查询课程数据
        List<SubjectTb>  subjectTbList=  subjectTbMapper.queryBatchSubjectInfoBySubjectIdList(subjectIdListInfo);
        ResultPage<SubjectTb> subjectTbResultPage = new ResultPage<>();
        subjectTbResultPage.setData(subjectTbList);
        return subjectTbResultPage;
    }
}
